import Vue from 'vue'
import Router from 'vue-router'
import url from '@/api/url'
import navjumper from '@/utils/navjumper'

import {Toast } from 'vant'
import 'vant/lib/index.css'

import layout from '@/App'
import page_index from '@/pages/index'
import page_other from '@/pages/other'


Vue.prototype.$url = url
Vue.prototype.$navjumper = navjumper
Vue.use(Router)

const mpDefault = new Router({
    mode : 'history',
    routes: [
        { path: '/(index)?', name: 'Index', component: page_index,}, 
    ],
})
const mpOther = new Router({
    mode : 'history',
    routes: [
        { path: '/other', name: 'Other', component: page_other,},
    ],
})
const webDefault = new Router({
    mode : 'history',
    routes: [
        { path: '/', redirect:{name : 'Index'}}, 
        { path: '/index', name: 'Index', component: page_index,},
        { path: '/other', name: 'Other', component: page_other,},
    ],
})



//路由拦截
const beforeF = function(to,form,next){
    Toast.loading({
        duration : 0, //持续展示
        message: '加载中...',
        forbidClick: true,
    });
            
    next();
}
const afterF = function(route, redirect){
    Toast.clear()
}
mpDefault.afterEach((route, redirect) => {
    afterF(route, redirect);
});
mpOther.afterEach((route, redirect) => {
    afterF(route, redirect);
});
webDefault.afterEach((route, redirect) => {
    afterF(route, redirect);
});

mpDefault.beforeEach((to, from, next) => {
    beforeF(to , from,next);
});
mpOther.beforeEach((to, from, next) => {
    beforeF(to , from,next);
});
webDefault.beforeEach((to, from, next) => {
    beforeF(to , from,next);
});

export default {
    //小程序路由入口
    mpDefault : mpDefault,
    mpOther : mpOther,
    //web路由入口
    webDefault : webDefault

}

